package com.jiangjiang.eshop.inventory.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiangjiang.eshop.inventory.domain.StockUpdateMessageEntity;
import com.jiangjiang.eshop.inventory.mapper.StockUpdateMessageMapper;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;
import java.util.List;

/**
 * @ClassName StockUpdateMessageService
 * @Description 库存更新消息service
 * @Author jhw
 * @Date 2021/6/14 17:24
 * @Version 1.0
 **/
@Service
public class StockUpdateMessageService extends ServiceImpl<StockUpdateMessageMapper, StockUpdateMessageEntity> {

    /**
     * 批量查询库存更新消息：每次50条
     * @return
     */
    public List<StockUpdateMessageEntity> listTop50() {
       return this.getBaseMapper().selectList(
                Wrappers.<StockUpdateMessageEntity>lambdaQuery()
                        .orderByAsc(StockUpdateMessageEntity::getGmtCreate)
                        .last("limit 50")
        );
    }

    /**
     * 批量删除message
     * @param messageIds
     */
    public void removeByBatch(List<String> messageIds) {
        LambdaQueryWrapper<StockUpdateMessageEntity> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.in(StockUpdateMessageEntity::getMessageId, messageIds);
        this.getBaseMapper().delete(queryWrapper);

    }
}
